package com.example.yskjproject.view.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.yskjproject.R;
import com.example.yskjproject.content.EventContent;
import com.example.yskjproject.event.EventMessage;
import com.example.yskjproject.http.Urls;
import com.example.yskjproject.http.callback.JsonCallback;
import com.example.yskjproject.model.LzyResponse;
import com.example.yskjproject.model.QRBindWxModel;
import com.example.yskjproject.model.WxScanCodeModel;
import com.example.yskjproject.utils.EventBusUtil;
import com.example.yskjproject.utils.SpCashUtils;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * ExitDialog
 * <p>
 * 作者：zx
 * 创建时间：2024/7/9
 */
public class ExitDialog extends Dialog {

    private String type;

    public ExitDialog(@NonNull Context context,String type) {
        super(context);
        setContentView(R.layout.exit_dialog);
        this.type = type;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams layoutParams = window.getAttributes();
            layoutParams.width = (int) (getContext().getResources().getDisplayMetrics().widthPixels * 0.8); // 设置宽度为500dp
            layoutParams.height = (int) (getContext().getResources().getDisplayMetrics().heightPixels * 0.28); // 设置高度为300dp
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            window.setAttributes(layoutParams);
        }
        AppCompatImageView img_colose = findViewById(R.id.img_colose);
        img_colose.setOnClickListener(close -> dismiss());
        AppCompatButton exitBtn = findViewById(R.id.exit_btn);
        exitBtn.setOnClickListener( exitApp ->{
            switch (type){
                case "exit":
                    SpCashUtils.getInstance().setToken(null);
                    System.exit(0);
                    break;
                case "home":
                    SpCashUtils.getInstance().setToken(null);
                    EventBusUtil.sendEvent(new EventMessage(EventContent.go_home));
                    dismiss();
                    break;


            }

        });
    }




}